#!/bin/bash

if [ ${#} -lt 1 ]
then
    echo "USAGE: ${0} doc_root"
    exit 1
fi

#strip the trailing slash
f=${1%\/}
f="${f}/"
fUp="${f}../"

#check for dir existance and writability
if [[ ! -d ${f} || ! -w ${f} || ! -d ${fUp} || ! -w ${fUp} ]]
then
    echo "ERROR: dir (${f} or ${fUp}) is not not writeable!"
    exit 2
fi

helpDir="./help/"

echo -e "\n*** Making dbdMVC App...\n"

#create dbdApp dir
echo "Creating 'dbdApp' skeleton dir in ${fUp}"
rsync -av --ignore-existing --exclude=".svn" ${helpDir}dbdApp ${fUp}

#copy htdocs dir
echo "Updating '${f}' dir with skeleton files"
rsync -av --ignore-existing --exclude=".svn" --include="*" --include=".htaccess" ${helpDir}htdocs/ ${f}

#make sure permissions are good
chmod 777 ${fUp}dbdApp/views/cache
chmod 777 ${fUp}dbdApp/views/templates_c

echo -e "\n\n*** Finished making dbdMVC App!\n"

exit 0
